﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace SimpleActor
{
    /// <summary>
    /// Represents the message handling status.
    /// </summary>
    public enum MessageHandlingStatus
    {
        /// <summary>
        /// The message has taken and handled.
        /// </summary>
        Handled,

        /// <summary>
        /// Timeout exceeded.
        /// </summary>
        TimedOut,

        /// <summary>
        /// The actor has requested to stop and all messages were handled.
        /// </summary>
        Completed,
    }

    /// <summary>
    /// Provides a set of static methods for <see cref="MessageHandlingStatus"/>.
    /// </summary>
    public static class MessageHandlingStatusExtensions
    {
        /// <summary>
        /// Gets the value indicating whether the actor servant can invoke <see cref="IMessageHandler.TryHandleMessage"/>
        /// </summary>
        /// <param name="value">the message handling status.</param>
        /// <returns>
        /// <c>true</c> if the the actor servant can invoke <see cref="IMessageHandler.TryHandleMessage"/>; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanNext(this MessageHandlingStatus value)
        {
            bool ret;
            switch (value)
            {
                case MessageHandlingStatus.Handled:
                case MessageHandlingStatus.TimedOut:
                    ret = true;
                    break;
                case MessageHandlingStatus.Completed:
                    ret = false;
                    break;
                default:
                    throw new InvalidEnumArgumentException("value", (int)value, typeof(MessageHandlingStatus));
            }
            return ret;
        }
    }
}
